Skip to content

Commit 9cc73ef

Browse files
Change default theme to system theme (#3649)
Co-authored-by: harmitgoswami <harmitgoswami@gmail.com>
1 parent 565b1ea commit 9cc73ef

File tree

8 files changed

+63
-20
lines changed

8 files changed

+63
-20
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Generated by Django 4.2.17 on 2025-01-29 18:43
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
dependencies = [
8+
("base", "0077_fix_android_newlines"),
9+
]
10+
11+
operations = [
12+
migrations.AlterField(
13+
model_name="userprofile",
14+
name="theme",
15+
field=models.CharField(
16+
choices=[("dark", "Dark"), ("light", "Light"), ("system", "System")],
17+
default="system",
18+
max_length=20,
19+
),
20+
),
21+
]

pontoon/base/models/user_profile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class Themes(models.TextChoices):
3535
theme = models.CharField(
3636
choices=Themes.choices,
3737
max_length=20,
38-
default=Themes.DARK,
38+
default=Themes.SYSTEM,
3939
)
4040

4141
# External accounts

pontoon/base/static/css/dark-theme.css

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/* Dark Theme Variables */
2-
.dark-theme,
3-
.system-theme {
2+
.dark-theme {
43
/* Main */
54
--main-border-1: #4d5967;
65
--moz-logo: url(../img/moz-logo-light.svg);

pontoon/base/static/css/style.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ header nav .right .sign-in-header button {
666666
background: transparent;
667667
border: 1.5px solid var(--status-translated);
668668
border-radius: 2px;
669-
color: white;
669+
color: var(--white-1);
670670
font-size: 14px;
671671
font-weight: 300;
672672
height: 40px;

pontoon/base/templates/django/base.html

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{% load static %}
22
{% load socialaccount %}
33
{% load helpers %}
4+
{% load django_helpers %}
45
<!doctype html>
56
<html lang="en" dir="ltr">
67
<head>
@@ -24,22 +25,14 @@
2425
<link rel="stylesheet" href="{% static 'css/boilerplate.css' %}" title="" type="text/css" />
2526
<link rel="stylesheet" href="{% static 'css/style.css' %}" title="" type="text/css" />
2627
<link rel="stylesheet" href="{% static 'css/dark-theme.css' %}" title="" type="text/css" />
28+
<link rel="stylesheet" href="{% static 'css/light-theme.css' %}" title="" type="text/css" />
2729

2830
{% include "tracker.html" %}
29-
30-
{% block extend_css %}
31-
<!-- Inlining CSS mitigates/prevents fouc. -->
32-
<style>
33-
body {
34-
background: #333941;
35-
}
36-
</style>
37-
{% endblock %}
3831
{% block extend_js %}
3932
{% endblock extend_js %}
4033
</head>
4134

42-
<body class="{% block class %}{% endblock %} dark-theme">
35+
<body class="{% block class %}{% endblock %} {{ request|theme_class }}" data-theme="{{ user|user_theme }}">
4336
<header>
4437
<ul class="notification">
4538
{% for message in messages %}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from django import template
2+
3+
4+
# We must redefine user_theme and theme_class with a new decorator in order
5+
# to use them in a Django template, such as in django/base.html
6+
7+
register = template.Library()
8+
9+
10+
@register.filter
11+
def user_theme(user):
12+
"""Get user's theme or return 'system' if user is not authenticated."""
13+
if user.is_authenticated:
14+
return user.profile.theme
15+
return "system"
16+
17+
18+
@register.filter
19+
def theme_class(request):
20+
"""Get theme class name based on user preferences and system settings."""
21+
theme = "system"
22+
user = request.user
23+
24+
if user.is_authenticated:
25+
theme = user.profile.theme
26+
27+
if theme == "system":
28+
theme = request.COOKIES.get("system_theme", "system")
29+
30+
return f"{theme}-theme"

pontoon/base/templatetags/helpers.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,23 +54,23 @@ def return_url(request):
5454

5555
@library.global_function
5656
def user_theme(user):
57-
"""Get user's theme or return 'dark' if user is not authenticated."""
57+
"""Get user's theme or return 'system' if user is not authenticated."""
5858
if user.is_authenticated:
5959
return user.profile.theme
60-
return "dark"
60+
return "system"
6161

6262

6363
@library.global_function
6464
def theme_class(request):
6565
"""Get theme class name based on user preferences and system settings."""
66-
theme = "dark"
66+
theme = "system"
6767
user = request.user
6868

6969
if user.is_authenticated:
7070
theme = user.profile.theme
7171

72-
if theme == "system":
73-
theme = request.COOKIES.get("system_theme", "system")
72+
if theme == "system":
73+
theme = request.COOKIES.get("system_theme", "system")
7474

7575
return f"{theme}-theme"
7676

translate/src/context/Theme.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export const ThemeContext = createContext({
77

88
export function ThemeProvider({ children }: { children: React.ReactElement }) {
99
const [theme] = useState(
10-
() => document.body.getAttribute('data-theme') || 'dark',
10+
() => document.body.getAttribute('data-theme') || 'system',
1111
);
1212

1313
const applyTheme = useTheme();

0 commit comments

Comments
 (0)